
SET QUOTED_IDENTIFIER ON
GO
SET ANSI_NULLS ON
GO

CREATE PROCEDURE [dbo].[gspFileAttach_SEARCH]
(
@attachId int = null,
@templateId int = null,
@siteContentId int = null,
@eventId int = null,
@documentName nvarchar(250) = null,
@documentType nvarchar(100) = null,
@documentSize int = null,
@isDeleted bit = null,
@createDate datetime = null,
@lastModifiedDate datetime = null
)
AS

SELECT
  *
FROM
  [dbo].[FileAttach]
WHERE
  (@attachId IS NULL OR [AttachId] = @attachId)
AND
  (@templateId IS NULL OR [TemplateId] = @templateId)
AND
  (@siteContentId IS NULL OR [SiteContentId] = @siteContentId)
AND
  (@eventId IS NULL OR [EventId] = @eventId)
AND
  (@documentName IS NULL OR @documentName = '' OR [DocumentName] LIKE @documentName + '%')
AND
  (@documentType IS NULL OR @documentType = '' OR [DocumentType] LIKE @documentType + '%')
AND
  (@documentSize IS NULL OR [DocumentSize] = @documentSize)
AND
  (@isDeleted IS NULL OR [IsDeleted] = @isDeleted)
AND
  (@createDate IS NULL OR [CreateDate] = @createDate)
AND
  (@lastModifiedDate IS NULL OR [LastModifiedDate] = @lastModifiedDate)

GO
